package models;

import objects.Constituent;
import objects.Lexicon;
import objects.LexiconList;
import objects.Stem;
import objects.Translation;

/* Generates the translation text */
public class GenerateTranslationModel {
	
	public GenerateTranslationModel() {}
	
	public static String generateTranslation(Constituent con) {
		String translated = "";
		Lexicon lexicon = LexiconModel.getLexicon();
		
		/* Find and set translation into constituent */
		for (LexiconList currentLexicon : lexicon.getLexiconList()) {
			if (currentLexicon.getLabel().toLowerCase().equals(con.getLabel().toLowerCase())) {
				for (Stem currentStem : currentLexicon.getStemList()) {
					try {
						if (con.getConcept().getName().toLowerCase().equals(currentStem.getConcept().toLowerCase())) {
							if (con.getSense().toLowerCase().equals(currentStem.getSense().toLowerCase())) {
								Translation translation = new Translation();
								translation.setName(currentStem.getValue());
								con.setTranslation(translation);
								
								translated += translation.getName();
							}
						}
					}
					catch (Exception ex) {}
				}
			}
		}
		
		/* Add ??? if concept has no translation */
		try {
			if (translated.equals("")) {
				if (con.getConcept().getName() != null) {
					translated += "???";
				}
			}
			
			for (Constituent currentCon : con.getConstituentList()) {
				translated = translated + " " + generateTranslation(currentCon);
			}
		}
		catch (Exception ex) {}
		
		translated = translated.trim();
		
		return translated;
	}
	
}
